﻿// <copyright file="ServiceAffector.cs" company="Beuth Hochschule für Technik">
// Breakdown - Configure your Windows 7 Firewall
// Copyright (C) 2009 Stefan "dersteps@gmail.com" Matyba
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 
// either version 3 of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/.
// </copyright>
// <author>Stefan Matyba</author>
// <email>dersteps@gmail.com</email>
// <date>2009-10-18</date>
// <summary>Breakdown Application Logic - Implementation of the IServiceAffector interface</summary>

namespace Breakdown.Logic
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using Breakdown.Aspects;

    /// <summary>
    /// Defines a service affector that can be used to decorate a firewall rule to make it affect services
    /// </summary>
    [Logged]
    public class ServiceAffector : IServiceAffector
    {
        /// <summary>
        /// The service affected by this affector
        /// </summary>
        private ServiceController _affectedService;
        
        /// <summary>
        /// If true, this affector affects all services
        /// </summary>
        private bool _affectsAllServices;

        /// <summary>
        /// Initializes a new instance of the ServiceAffector class. By default, the affector affects all services
        /// </summary>
        public ServiceAffector()
        {
            this._affectsAllServices = true;
        }

        /// <summary>
        /// Gets or sets the service affected by this affector. Is null if this affector affects all services
        /// </summary>
        public ServiceController AffectedService
        {
            get { return this._affectedService; }
            set { this._affectedService = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether or not this affector affects all services.
        /// </summary>
        public bool AffectsAllServices
        {
            get { return this._affectsAllServices; }
            set 
            { 
                this._affectsAllServices = value;
                this._affectedService = value ? null : this._affectedService;
            }
        }
    }
}
